#include "CloudMoniter.h"
#include <iostream>
#include <string>
using namespace std;
int CloudMoniter::uploadFile(string name, string buf)
{
    /* 初始化网络等资源。*/
    InitializeSdk();

    // 1. 初始化OSS账号信息
    std::string endpoint = "oss-cn-wuhan-lr.aliyuncs.com";
    std::string accessKeyId = "LTAI5tMWhmmvMYQYFLc2xqfp";
    std::string accessKeySercret = "8HGY1S8pLyjGx40uvvR5pR5mBkOhT4";
    std::string region = "cn-wuhan";

    ClientConfiguration conf;
    OssClient client {endpoint ,accessKeyId, accessKeySercret, conf};
    client.SetRegion(region);

    std::string bucketName = "passion-jhc";
    std::string objectName = "dir-demo/"+name;

    std::string content = buf;
    std::shared_ptr<std::iostream> stream = std::make_shared<std::stringstream>(std::move(buf));

    PutObjectRequest request { bucketName, objectName, stream };

    auto outcome = client.PutObject(request);

    if (!outcome.isSuccess()) {
        /* 异常处理。*/
        std::cout << "PutObject fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        return -1;
    }

    /* 释放网络等资源。*/
    ShutdownSdk();
    return 0;
}

